//
//  ShippingAddressTableViewCell.m
//  FactorySale
//
//  Created by 主事丫环 on 2020/3/27.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "ShippingAddressTableViewCell.h"

@implementation ShippingAddressTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        UIView *bottomV = [[UIView alloc] init];
        bottomV.backgroundColor = [UIColor whiteColor];
        bottomV.frame = CGRectMake(0, 0, KWIDTH, 97);
        //bottomV.frame = CGRectMake(0, 0, KWIDTH - 20, 107);
        //bottomV.layer.cornerRadius = 10;
        //bottomV.layer.masksToBounds = YES;
        //bottomV.layer.borderWidth = 1;
        //bottomV.layer.borderColor = [UIColor colorWithHexString:@"#70BE68"].CGColor;
        [self.contentView addSubview:bottomV];
        
        //设置默认地址 按钮
        UIButton *defaultBtn = [[UIButton alloc] init];
        defaultBtn.frame = CGRectMake(15, 45.5, 20, 20);
        [defaultBtn setImage:[UIImage imageNamed:@"defaultSelect"] forState:UIControlStateNormal];
        [defaultBtn addTarget:self action:@selector(setDefaultAddressBtn:) forControlEvents:UIControlEventTouchUpInside];
        [bottomV addSubview:defaultBtn];
        self.defaultBtn = defaultBtn;
        
        //编辑地址 按钮
        UIButton *editBtn = [[UIButton alloc] init];
        editBtn.frame = CGRectMake(bottomV.right-40, 12.5, 25, 25);
        [editBtn setImage:[UIImage imageNamed:@"editAddress"] forState:UIControlStateNormal];
        [editBtn addTarget:self action:@selector(editAddressBtn:) forControlEvents:UIControlEventTouchUpInside];
        [bottomV addSubview:editBtn];
        self.editBtn = editBtn;
        
        //默认地址
        UILabel *defaAddLab = [[UILabel alloc] init];
        defaAddLab.frame = CGRectMake(45.5, 10, 60, 12);
        defaAddLab.text = @"默认地址";
        defaAddLab.font = KFontPingFangSCMedium(12);
        defaAddLab.textColor = [UIColor colorWithHexString:@"#31CEA9"];
        [bottomV addSubview:defaAddLab];
        self.defaAddLab = defaAddLab;
        //姓名 标题
        UILabel *nameLab = [[UILabel alloc] init];
        nameLab.frame = CGRectMake(45.5, defaAddLab.bottom + 5, 70, 20);
        nameLab.font = KFontPingFangSCMedium(13);
        nameLab.textColor = K666666;
        [bottomV addSubview:nameLab];
        self.nameLab = nameLab;
        //电话 内容
        UILabel *phoneLab = [[UILabel alloc] init];
        phoneLab.frame = CGRectMake(nameLab.right, defaAddLab.bottom + 5, KWIDTH-20-12-48-12-70-12, 20);
        phoneLab.font = KFontPingFangSCMedium(13);
        phoneLab.textColor = K999999;
        [bottomV addSubview:phoneLab];
        self.phoneLab = phoneLab;
        //详细地址
        UILabel *addressLab = [[UILabel alloc] init];
        addressLab.frame = CGRectMake(45.5, nameLab.bottom +5, KWIDTH - 45.5*2, 36);
        addressLab.numberOfLines = 0;
        addressLab.font = KFontPingFangSCMedium(12);
        addressLab.textColor = [UIColor colorWithHexString:@"#333333"];
        [bottomV addSubview:addressLab];
        self.addressLab = addressLab;

    }
    return self;
}

//- (void)refasf:(ShippingAddressListModel *)model{
- (void)refasf:(SelectAreaModel *)model{
    self.nameLab.text = model.name;       //姓名
    self.phoneLab.text = model.phone;     //电话
    self.addressLab.text = model.address; //详细地址
    
    NSString *defaultStr = [NSString stringWithFormat:@"%@",model.is_default];
    
    if ([defaultStr isEqualToString:@"0"]) {
        self.defaAddLab.hidden = YES;
        self.defaultBtn.hidden = YES;
    } else {
        //self.defaAddLab.text = @"默认地址";
        self.defaAddLab.hidden= NO;
        [self.defaultBtn setImage:imgname(@"defaultSelect") forState:UIControlStateNormal];
        self.defaultBtn.hidden = NO;
    }
}

//设置默认地址地址 按钮 点击事件处理
- (void)setDefaultAddressBtn:(UIButton *)button {
    NSLog(@"设置默认地址");
    if (self.editOrDelBlock) {
        self.editOrDelBlock(0);//设置默认地址
    }
}

//编辑地址 按钮 点击事件处理
- (void)editAddressBtn:(UIButton *)button {
    NSLog(@"编辑");
    kWeakSelf;
    if (weakSelf.editOrDelBlock) {
        weakSelf.editOrDelBlock(1);//编辑地址
    }
}

@end
